<template>
	<div class="app-container">

		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
				<el-form-item label="辅导员姓名" prop="teacherName">
					<el-input v-model="queryParams.teacherName" placeholder="请输入辅导员姓名" clearable
						@keyup.enter.native="handleQuery" />
				</el-form-item>
				<el-form-item label="学院" prop="teacherCollege">
					<el-select v-model="queryParams.teacherCollege" placeholder="请选择学院" :disabled="chooseCollege"
						clearable>
						<el-option v-for="dict in dict.type.rt_filling_college" :key="dict.value" :label="dict.label"
							:value="dict.value" />
					</el-select>
				</el-form-item>
			<el-form-item label="审核年度" prop="checkYear">
				<el-select v-model="queryParams.checkYear" placeholder="请选择年度" clearable>
					<el-option v-for="dict in dict.type.sys_teacher_kpi_filling_year" :key="dict.value"
						:label="dict.label" :value="dict.value" />
				</el-select>
			</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
					<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
				</el-form-item>
			
		</el-form>
			<el-row :gutter="10" class="mb8">
				<el-col :span="1.5">
					<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
						v-hasPermi="['teacher:achievementcheck:export']">导出</el-button>
				</el-col>
				<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
			</el-row>
	
		<el-table v-loading="loading" :data="achievementcheckList" @selection-change="handleSelectionChange"
			:default-sort="{prop:'lastTime',order:'descending'}">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="成果绩效ID" align="center" prop="checkId" v-if="false" />
			<el-table-column label="工号" align="center" prop="teacherId" />
			<el-table-column label="辅导员姓名" align="center" prop="teacherName" />
			<el-table-column label="辅导员学院" align="center" prop="teacherCollege">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.rt_filling_college" :value="scope.row.teacherCollege" />
				</template>
			</el-table-column>
			<el-table-column label="审核年度" align="center" prop="checkYear">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.sys_teacher_kpi_filling_year" :value="scope.row.checkYear" />
				</template>
			</el-table-column>
			<el-table-column label="提交时间" align="center" prop="submitTime">
				<template slot-scope="scope">
					{{scope.row.submitTime |formatDate}}
				</template>
			</el-table-column>
			<el-table-column label="退回原因" align="center" prop="returnReason" />
			<el-table-column label="审核状态" align="center" prop="checkStatus">
				<template slot-scope="scope">
					<el-tag :type="currentType(scope.row.checkStatus)">
						{{currentStatus(scope.row.checkStatus)}}
					</el-tag>

				</template>
			</el-table-column>

			<el-table-column label="审核人" align="center" prop="checkPerson" />
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
					<template slot-scope="scope">
						<el-button size="mini" type="text" icon="el-icon-edit" @click="detail(scope.row)"
							v-hasPermi="['teacher:achievementcheck:edit']">详情</el-button>
					</template>
				</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />
		<!-- 详情对话框 -->
		<el-dialog v-if="dialogReset" title="成果审批详情" :visible.sync="detailDialog" width="1500px" @close="dialogClose"
			append-to-body>
			<el-steps :active="roleStatus" finish-status="success">
				<el-step title="学务办初审" :description="suggestContent1"></el-step>
				<el-step title="党总支书记审批" :description="suggestContent2"></el-step>
				<el-step title="科室复核" :description="suggestContent3"></el-step>
				<el-step title="学工处长审核" :description="suggestContent4"></el-step>
			</el-steps>
			<el-tabs type="border-card">
				<el-tab-pane label="论文成果">
					<thesis :message="teacherId"></thesis>
				</el-tab-pane>
				<el-tab-pane label="课题研究">
					<research :message="teacherId"></research>
				</el-tab-pane>
				<el-tab-pane label="工作案例">
					<workexample :message="teacherId"></workexample>
				</el-tab-pane>
				<el-tab-pane label="指导参赛">
					<guidance :message="teacherId"></guidance>
				</el-tab-pane>
				<el-tab-pane label="个人参赛">
					<contest :message="teacherId"></contest>
				</el-tab-pane>
				<el-tab-pane label="个人荣誉">
					<honor :message="teacherId"></honor>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>

		<!-- 12月开放对话框 -->
		<el-dialog title="功能未开放" :visible.sync="open" width="500px" append-to-body>
			本功能只在12月开放！
			<div slot="footer" class="dialog-footer">

				<el-button @click="close">确 定</el-button>
			</div>
		</el-dialog>

	</div>
</template>

<script>
	import {
		getUserProfile
	} from "@/api/system/user";
	import {
		listAchievementcheck,
		getAchievementcheck,
		delAchievementcheck,
		addAchievementcheck,
		updateAchievementcheck
	} from "@/api/teacher/achievementcheck";
	import {
		listThesis,
		getThesis,
		delThesis,
		addThesis,
		updateThesis
	} from "@/api/teacher/thesis";
	import {
		listResearch,
		getResearch,
		delResearch,
		addResearch,
		updateResearch
	} from "@/api/teacher/research";
	import {
		listWorkexample,
		getWorkexample,
		delWorkexample,
		addWorkexample,
		updateWorkexample
	} from "@/api/teacher/workexample";
	import {
		listGuidance,
		getGuidance,
		delGuidance,
		addGuidance,
		updateGuidance
	} from "@/api/teacher/guidance";
	import {
		listContest,
		getContest,
		delContest,
		addContest,
		updateContest
	} from "@/api/teacher/contest";
	import {
		listHonor,
		getHonor,
		delHonor,
		addHonor,
		updateHonor
	} from "@/api/teacher/honor";
	//辅导员论文成果组件
	import thesis from '@/views/teacher/achievement/achievementCheck/thesis/index.vue'
	//辅导员课题研究组件
	import research from '@/views/teacher/achievement/achievementCheck/research/index.vue'
	//辅导员工作案例组件
	import workexample from '@/views/teacher/achievement/achievementCheck/workexample/index.vue'
	//辅导员指导参赛组件
	import guidance from '@/views/teacher/achievement/achievementCheck/guidance/index.vue'
	//辅导员个人参赛组件
	import contest from '@/views/teacher/achievement/achievementCheck/contest/index.vue'
	//辅导员个人荣誉组件
	import honor from '@/views/teacher/achievement/achievementCheck/honor/index.vue'


	export default {
		name: "index",
		components: {
			thesis,
			research,
			workexample,
			guidance,
			contest,
			honor
		},
		dicts: ['rt_thesislevel', 'sys_teacher_kpi_filling_year', 'rt_filling_college', 'rt_reason'],
		data() {
			return {
				teacherId: null,
				currentId:null,
				//当前用户角色、姓名、学院
				currentRole: [],
				currentName: null,
				currentCollege: null,
				roleStatus: 0,
				//当前成果ID
				achievementId: null,
				//功能开放情况 
				open: false,
				//是否允许审批
				checkBtn: null,
				//是否辅导员进入
				isteacher: true,
				//详情开关
				detailDialog: false,
				dialogReset: false,
				//是否允许选择学院
				chooseCollege: false,
				//退回理由
				reason: null, //对话框
				returnReason: null,
				//审核意见
				suggest:false,
				checkSuggest:null,
				suggestContent1:"审核意见：",
				suggestContent2:"审核意见：",
				suggestContent3:"审核意见：",
				suggestContent4:"审核意见：",
				//是否驳回
				kill: false,
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				teacherids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// achievementcheck表格数据
				achievementcheckList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					teacherId: null,
					teacherName: null,
					teacherCollege: null,
					thesisTitle: null,
					thesisPublication: null,
					researchName: null,
					researchLevel: null,
					workexampleName: null,
					workexampleLevel: null,
					guidanceProject: null,
					guidanceAwardlevel: null,
					contestProject: null,
					contestAwardlevel: null,
					honorName: null,
					honorLevel: null,
					checkStatus: null,
					checkYear: null,
					checkPerson: null,
					thesisId: null,
					researchId: null,
					workexampleId: null,
					guidanceId: null,
					contestId: null,
					honorId: null
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					teacherId: [{
						required: true,
						message: "辅导员ID不能为空",
						trigger: "blur"
					}],
				}
			};
		},
		created() {
			// var month = new Date().getMonth() + 1;
			// if(month!=12){
			// 	this.open=true;
			// }
			// else{
			this.getRole();


			// }
		},
		methods: {
			getRole() {
				getUserProfile().then(response => {
					this.currentId = response.data.userName;
					this.currentName = response.data.nickName;
					this.currentCollege = response.data.dept.deptName;

					for (var i = 0; i < response.data.roles.length; i++) {
						this.currentRole.push(response.data.roles[i].roleName);
					}
					if (this.currentRole.includes('超级管理员')) {

					} else if (this.currentRole.includes('辅导员管理学工处长')) {
						this.queryParams.teacherCollege = "水利工程学院";

					} else if (this.currentRole.includes('辅导员管理科室复核')) {
						this.queryParams.teacherCollege = "水利工程学院";


					} else if (this.currentRole.includes('辅导员管理党总支书记')) {
						this.queryParams.teacherCollege = response.data.dept.deptName;
						this.chooseCollege = true;

					} else if (this.currentRole.includes('辅导员管理学务办初审')) {
						this.queryParams.teacherCollege = response.data.dept.deptName;
						this.chooseCollege = true;

					} else if (this.currentRole.includes('辅导员')) {
						this.queryParams.teacherId = response.data.userName;
						this.isteacher = false;
					}
					this.loading = true;
					this.queryParams.checkYear = new Date().getFullYear();
					this.queryParams.thesisPublication = this.currentId;
					listAchievementcheck(this.queryParams).then(response => {
						this.achievementcheckList = response.rows;
						this.total = response.total;
						this.loading = false;
					});

				});

			},
			close() {
				this.$router.go(-1);
			},
			/** 查询achievementcheck列表 */
			getList() {
				this.loading = true;
				listAchievementcheck(this.queryParams).then(response => {
					this.achievementcheckList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reason = false;
				this.suggest=false;
				this.achievementId = null;
				this.teacherId = null;
				this.kill = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					checkId: null,
					teacherId: null,
					teacherName: null,
					thesisTitle: null,
					thesisPublication: null,
					researchName: null,
					researchLevel: null,
					workexampleName: null,
					workexampleLevel: null,
					guidanceProject: null,
					guidanceAwardlevel: null,
					contestProject: null,
					contestAwardlevel: null,
					honorName: null,
					honorLevel: null,
					checkStatus: null,
					checkYear: null,
					checkPerson: null,
					thesisId: null,
					researchId: null,
					workexampleId: null,
					guidanceId: null,
					contestId: null,
					honorId: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.queryParams.teacherCollege = this.currentCollege;
				this.queryParams.thesisPublication = this.currentId;
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.checkId);
				this.teacherids = selection.map(item => item.teacherId);
				this.single = selection.length !== 1;
				var c = this;

				if (selection.length != 0) {
					for (var i = 0; i < c.ids.length; i++) {
						var aId = c.ids[i];
						getAchievementcheck(aId).then(response => {
							if (response.data.checkStatus == 0 || response.data.checkStatus == 5) {
								c.multiple = true;
							} else {
								c.multiple = !selection.length;
							}
						});
					}
				} else {
					c.multiple = !selection.length;
				}


			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('teacher/achievementcheck/export', {
					...this.queryParams
				}, `成果绩效导出_${new Date().getTime()}.xlsx`)
			},
			detail(row) {
				if (row.checkStatus == 0) {
					this.roleStatus = 0;
				} else if (row.checkStatus == 1) {
					this.roleStatus = 0;
				} else if (row.checkStatus == 2) {
					this.roleStatus = 1;
				} else if (row.checkStatus == 3) {
					this.roleStatus = 2;
				} else if (row.checkStatus == 4) {
					this.roleStatus = 3;
				} else if (row.checkStatus == 5) {
					this.roleStatus = 5;
				}
				this.achievementId = row.checkId;
				this.teacherId = row.teacherId;
				this.checkBtn = row.checkStatus;
				this.dialogReset = true;
				this.checkDesc();
			
				this.detailDialog = true;
			},
			currentStatus(status) {
				var c = this;
				if (status == 0) {
					return "已驳回";
				} else if (status == 1) {

					return "待审核";
				} else if (status == 2) {

					return "学务办初审通过 ";
				} else if (status == 3) {

					return "党总支书记审核通过";
				} else if (status == 4) {

					return "科室复核通过";
				} else if (status == 5) {

					return "学工处长审核通过";
				}
			},
			currentType(status) {
				var c = this;
				if (status == 0) {
					return "danger";
				} else if (status == 1) {
					return "primary";
				} else if (status == 2) {

					return "warning";
				} else if (status == 3) {

					return "warning";
				} else if (status == 4) {

					return "warning";
				} else if (status == 5) {

					return "success";
				}
			},
			compareRole(row) {
				var c = this;
				if (row.checkStatus == 0 || row.checkStatus == 5) {
					return false;
				} else if (c.currentRole.includes('超级管理员')) {
					return true;
				} else if (c.currentRole.includes('辅导员管理学工处长') && row.checkStatus == 4) {
					return true;
				} else if (c.currentRole.includes('辅导员管理科室复核') && row.checkStatus == 3) {
					return true;
				} else if (c.currentRole.includes('辅导员管理党总支书记') && row.checkStatus == 2) {
					return true;
				} else if (c.currentRole.includes('辅导员管理学务办初审') && row.checkStatus == 1) {
					return true;
				} else {
					return false;
				}

			},
			compareRole2() {
				var c = this;
				
				if (c.checkBtn == 0 || c.checkBtn == 5) {
					return false;
				} else if (c.currentRole.includes('超级管理员')) {
					return true;
				} else if (c.currentRole.includes('辅导员管理学工处长') && c.checkBtn == 4) {
					return true;
				} else if (c.currentRole.includes('辅导员管理科室复核') && c.checkBtn == 3) {
					return true;

				} else if (c.currentRole.includes('辅导员管理党总支书记') && c.checkBtn == 2) {
					return true;
				} else if (c.currentRole.includes('辅导员管理学务办初审') && c.checkBtn == 1) {
					return true;
				} else {
					return false;
				}
			},
			dialogClose() {
				this.dialogReset = false;
			},
			checkDesc(){
				var c = this;
				getAchievementcheck(c.achievementId).then(response => {
					if(response.data.thesisTitle==null){
						c.suggestContent1 = "待审核";
					}else{
						c.suggestContent1 = "审核意见："+ response.data.thesisTitle;
					}
					if(response.data.researchName==null){
						c.suggestContent2 = "待审核";
					}else{
						c.suggestContent2 = "审核意见："+ response.data.researchName;
					}
					if(response.data.workexampleName==null){
						c.suggestContent3 = "待审核";
					}else{
						c.suggestContent3 = "审核意见："+ response.data.workexampleName;
					}
					if(response.data.guidanceProject==null){
						c.suggestContent4 = "待审核";
					}else{
						c.suggestContent4 = "审核意见："+ response.data.guidanceProject;
					}
					
				});
				
			},
			updateList(){
				listAchievementcheck(this.queryParams).then(response => {
					this.achievementcheckList = response.rows;
					this.total = response.total;
				});
			}
		}
	};
</script>
<style>
	.el-divider__text {
		font-size: 20px;
		font-weight: bold;
	}
</style>